<?php
 require "./class_tree.php";
 require "../array/tool_array.php";
 require "./tool_tree.php";
 require "./class_drawer_svg.php";
 require "../misc/tool_color.php";
 
 $a=new tree("a",array(),"a");
 $b=new tree("b",array(),"b",$a);
 $c=new tree("c",array(),"c",$a);
 $d=new tree("d",array(),"d",$a);
 $e=new tree("e",array(),"e",$a);
 $f=new tree("f",array(),"f",$e);
 $g=new tree("g",array(),"g",$e);
 $h=new tree("h",array(),"h",$e);

 $a1=new tree("a",array(),"A");
 $b1=new tree("b",array(),"B",$a1);
 $c1=new tree("c",array(),"C",$a1);
 $d1=new tree("d",array(),"D",$a1);
 $e1=new tree("e",array(),"E",$a1);
 $f1=new tree("f",array(),"F",$e1);
 $g1=new tree("g",array(),"G",$e1);
 $h1=new tree("h",array(),"H",$e1);
// $e1=new tree("e",array(),"E",$a1);

// $a->__add_tree($b);
// $a->__add_tree($c);
// $a->__add_tree($b);
// $c->__add_tree($d);
// $c->__add_tree($e);
 $a->__add_tree($b);
 $a->__add_tree($c);
// $a->__add_tree($f);


// $a1->__add_tree($b1);
// $c1->__add_tree($d1);
 $a1->__add_tree($c1);
 $a1->__add_tree($b1);
// $a1->__add_tree($d1);
// $e1->__add_tree($g1);
// $e1->__add_tree($h1);
// $a1->__add_tree($e1);
// $a1->__add_tree($f1);


// $a1->__add_tree($b1);
// $b1->__add_tree($d1);
// $a1->__add_tree($c1);

//echo tool_tree::tree2txt($a);
//echo tool_tree::tree2txt($a1);

$forest = new forest(array($a));
$forest1 = new forest(array($a1));

//echo tool_forest::forest2txt($forest);
//echo tool_forest::forest2txt($forest1);
//print_r(tool_forest::forest2rightdec($forest));
$ted=new TED_shasha();
$ted->__init($forest,$forest1);
//echo Tool_ted::ted2html($ted,$forest,$forest1);
$option=array(
 "print"=>"numeric",
 "numeric"=>null
);

$header_xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:svg=\"http://www.w3.org/2000/svg\">
<head>
  <style>
    table{
      border-spacing:0px;
      border:solid black 1px;
    }
    td{
      border:solid grey 1px;
    }
  </style>
</head>
<body>
";

echo $header_xml;

echo Tool_ted::ted2svg($ted,$forest,$forest1,$option);
echo Tool_ted::ted_trace2svg($ted,$forest,$forest1,$option);
echo "</body></html>";
//print_r($ted);
//die();

//print_r($ted);

die();

 $a1->__add_tree($b1);
 $a1->__add_tree($c1);
 $a1->__add_tree($d1);

//echo tool_tree::tree2txt($a);
//$a_reverse=$a->__get_reverse(); 
//echo tool_tree::tree2txt($a_reverse);
//echo $a->__get_height();
//echo $a->__get_width();
//die();

//print_r($a->__traverse_large());

//echo tool_tree::tree2txt($a);
//echo $a->__get_width();
//die();

$forest = new forest(array($a));
$forest1 = new forest(array($a1));
//$forest1->__recalc_n();
/*
 $c=new tree("c",array(),2,$a);
 $d=new tree("d",array(),3,$a);
 $e=new tree("e",array(),4,$b);
 $f=new tree("f",array(),5,$e);
 $g=new tree("g",array(),6,$c);
*/

// $c->__add_tree($g);
// $b->__add_tree($e);
// $a->__add_tree($b);
// $a->__add_tree($c);
// $a->__add_tree($d);

//$test=new RecursiveIteratorIterator($a,RecursiveIteratorIterator::CHILD_FIRST);

//foreach($test as $dd){
// echo $dd;
// echo "\n";
//}

//echo $b;
//die();


//die();
//$forest_copy = new forest(array($a));

$ted=new TED_shasha();
$ted->__init($forest,$forest1);

//echo tool_forest::forest2txt($forest);
//echo tool_forest::forest2txt($forest1);

echo Tool_ted::ted2txt($ted);
//print_r($ted);

die();
echo "\n";

$test=new RecursiveIteratorIterator($forest,RecursiveIteratorIterator::CHILD_FIRST);

//echo $forest;
//echo "\n";

//***************
//test recalc_n
//***************
$forest->__recalc_n();
$test=new RecursiveIteratorIterator($forest,RecursiveIteratorIterator::CHILD_FIRST);

/*
foreach($test as $tree){
 echo $tree->__get_n();
 echo $tree;
 echo "\n";
}
*/

/*
foreach($test as $dd){
 echo $dd;
 echo "\n";
}
*/
//$forest=$forest->__del_left();
//$test=new RecursiveIteratorIterator($forest,RecursiveIteratorIterator::CHILD_FIRST);

//echo $forest;
//echo "\n";

//$forest=$forest->__del_right();
//$test=new RecursiveIteratorIterator($forest,RecursiveIteratorIterator::CHILD_FIRST);

//echo $forest;
//echo "\n";

//***************
//test match left
//***************

/*
list($a,$b)=$forest->__match_left();
$res=$forest->__match_left();
echo $a;
echo $res[0];
echo "\n";
echo $b;
echo $res[1];
//echo "\n";
*/
/*
foreach($test as $dd){
 echo $dd;
 echo "\n";
}
*/
//$forest->__free();

//print_r($forest);
//print_r($a);

?>
